from BaseController import BaseController
from Common.MTurk.GetAccountBalanceParams import GetAccountBalanceParams
from Biz import MTurkRequester


class GetAccountBalanceTestController(BaseController):
    def get(self):
        p = GetAccountBalanceParams()
        result = MTurkRequester.SendMTurkRequest(p)
        
        if None is not result: 
            #errors_nodes = result.getElementsByTagName('FormattedPrice')[0].childNodes[0].data
            #for errors_node in errors_nodes:
            #    for error_node in errors_node.getElementsByTagName('Error'):
            #        error_node.getElementsByTagName('Code')[0].childNodes[0].data
            #        error_node.getElementsByTagName('Message')[0].childNodes[0].data
            template_values = {
                               'RESULT': result.getElementsByTagName('FormattedPrice')[0].childNodes[0].data
                               }
        else:
            template_values = {
                               'RESULT': 'There is some wrong~'
                               }
        
        self.Render('demo.html', template_values)
        
    
    def post(self):
        self.get()